package com.example.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.entity.AdminSkuAttrValueExam;
import com.example.entity.AdminSkuExam;
import com.example.entity.Attr;
import com.example.mapper.AttrMapper;
import com.example.service.AdminSkuExamService;
import com.example.mapper.AdminSkuExamMapper;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;

/**
* @author 12057
* @description 针对表【admin_sku_exam(sku信息)】的数据库操作Service实现
* @createDate 2024-06-09 19:59:10
*/
@Service
public class AdminSkuExamServiceImpl extends ServiceImpl<AdminSkuExamMapper, AdminSkuExam>
    implements AdminSkuExamService{
    @Resource
    AttrMapper attrMapper;
    @Override
    public Long addAttr(AdminSkuAttrValueExam skuAttrValueExam) {
        QueryWrapper<Attr> queryWrapper = new QueryWrapper<>();

        queryWrapper.eq("name",skuAttrValueExam.getAttrName());

        Long attrId = 0L;

        if(attrMapper.exists(queryWrapper)){
            Attr attr = attrMapper.selectOne(queryWrapper);
            attr.setValueSelect(attr.getValueSelect()+","+skuAttrValueExam.getAttrValue());

            attrMapper.insert(attr);

            attrId=attr.getId();
        }else {
            Attr attr = new Attr();
            attr.setValueSelect(skuAttrValueExam.getAttrValue());
            attr.setName(skuAttrValueExam.getAttrName());

            attrMapper.insert(attr);

            attrId=attr.getId();
        }

        return attrId;
    }
}




